<template>
  <view class="commission-details" ref="container">
    <view class="promoterHeader bg-color-red">
      <view class="headerCon acea-row row-between-wrapper">
        <view>
          <view class="name">余额</view>
          <view class="money">
            ￥
            <text class="num">{{ nowMoney }}</text>
			<button size="mini" style="vertical-align: text-bottom; margin: 0 60rpx;" @click="goUserCash()">提现</button>
          </view>
        </view>
        <view class="iconfont icon-jinbi1"></view>
      </view>
    </view>
    <view class="sign-record" ref="content">
      <view class="list">
        <view class="item" v-for="(item, infoIndex) in info" :key="infoIndex">
          <view class="data">{{ item.time }}</view>
          <view class="listn" v-for="(val, indexn) in item.list" :key="indexn">
            <view class="itemn acea-row row-between-wrapper">
              <view>
                <view class="name line1">{{typeMap[val.type]}} | {{ val.title }}</view>
                <view>{{ val.addTime }}</view>
              </view>
              <view class="num" v-if="val.pm == 1">+{{ val.number }}</view>
              <view class="num font-color-red" v-if="val.pm == 0">-{{ val.number }}</view>
            </view>
          </view>
        </view>
      </view>
    </view>
    <Loading :loaded="loaded" :loading="loading"></Loading>
  </view>
</template>
<script>
// import { getCommissionInfo, getSpreadInfo } from "@/api/user";
import {
		mapGetters
	} from "vuex";
import {
		commissionApp
	} from "@/api/user";
import Loading from "@/components/Loading";

export default {
  name: "CashRecord",
  components: {
    Loading
  },
  props: {},
  data: function() {
    return {
      info: [],
      commission: 0,
      where: {
        page: 1,
        limit: 10,
		
		// 扩展
		type1: 1
      },
      types: 1,
      loaded: false,
      loading: false,
	  
	  typeMap: {
	  	'pay_product': '消费',
	  	'recharge': '充值',
	  	'brokerage': '返佣',
	  	'extract': '提现',
	  	'sign': '签到积分',
	  	'pay_product_refund': '退款',
	  	'system_add': '系统增加',
	  	'system_sub': '系统减少',
	  	'deduction': '减去',
	  	'gain': '奖励',
	  	'price_difference': '差价',
		'convert': '待收益转入',
		'pay_product': '消费',
		'scan_pay': '扫码付款',
		'pay_vip': '购买VIP',
		'scan_collection': '二维码收款'
	  },
	  nowMoney: 0
    };
  },
  mounted: function() {
    // this.getCommission();
    // this.getIndex();
	this.nowMoney = this.$yroute.query.nowMoney
	this.loadData()
  },
  onReachBottom() {
    this.loading === false && this.loadData();
  },
  computed: mapGetters(["userInfo"]),
  methods: {
	  goUserCash() {
		// 开通门店需要判断用户是否实名认证
		if (!this.userInfo.realName) return uni.showToast({
			title: '请先完成实名认证！',
			icon: "none",
			duration: 2000
		});
		this.goRouter(`/userPack/pages/user/promotion/UserCash/index`)
	  },
	  loadData() {
	  	let that = this;
		if (that.loading == true || that.loaded == true) return;
		that.loading = true;
	  	commissionApp(that.where, 0).then(
	  		res => {
	  			that.loading = false;
				console.log(res.data)
				if (res.data) {
					that.loaded = res.data[0].list.length < that.where.limit;
					that.where.page = that.where.page + 1;
					that.info.push.apply(that.info, res.data);
					console.log(that.loaded)
				} else {
					that.loaded = false
				}
	  			
	  		},
	  		err => {
	  			uni.showToast({
	  				title: err.msg || err.response.data.msg || err.response.data.message,
	  				icon: 'none',
	  				duration: 2000
	  			});
	  		}
	  	);
	  },
    getIndex: function() {
      let that = this;
      if (that.loading == true || that.loaded == true) return;
      that.loading = true;
      getCommissionInfo(that.types).then(
        res => {
          that.loading = false;
          that.loaded = res.data.length < that.where.limit;
          that.where.page = that.where.page + 1;
          that.info.push.apply(that.info, res.data);
        },
        err => {
          uni.showToast({
				title: err.msg || err.response.data.msg|| err.response.data.message,
				icon: 'none',
				duration: 2000
			});
        }
      );
    },
    // getCommission: function() {
    //   let that = this;
    //   getSpreadInfo().then(
    //     res => {
    //       that.commission = res.data.commissionCount;
    //     },
    //     err => {
    //       uni.showToast({
    //         title: err.msg || err.response.data.msg|| err.response.data.message,
    //         icon: "none",
    //         duration: 2000
    //       });
    //     }
    //   );
    // },
	goRouter(url) {
		this.$yrouter.push({path: url});
	}
  }
};
</script>
